package com.toolenaar.socialiceThis;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;



public class FriendsTabViewXml extends Activity {

	
    private ListView _list;
    private static final String friendsXML = "socialicethisfriendlist.xml";
    
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		
		_list = new ListView(this.getBaseContext());
		setContentView(_list);
		try {
			readXmlFile();
		} catch (XmlPullParserException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

	 private void readXmlFile() throws XmlPullParserException, IOException{
		 
    	 XmlPullParser parser = (XmlPullParser)getResources().getXml(R.xml.socialicethisfriendlist);
    	 
    	 
    	 //fill array with strings from xml and add to listview
    	 
    	 ArrayList<String> items=new ArrayList<String>();
    	 int i = 0; 
    	 int eventType = parser.getEventType();
    	 
    	 while (eventType != XmlPullParser.END_DOCUMENT) {
    		 
    		 if (eventType==XmlPullParser.START_TAG) {
    			 Log.i("FriendsTabViewXml", parser.getName());
					if (parser.getName().equals("name")) {
						eventType = parser.next();
						if(eventType == XmlPullParser.TEXT) {
							
							items.add(parser.getText());
						}	
					}
				}
    		 eventType = parser.next();
    	 }
    	 
 		_list.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,items));
    	
    }
}
